package com.authine.cloudpivot.web.api.controller;
import com.authine.cloudpivot.engine.api.model.organization.UserModel;
import com.authine.cloudpivot.web.api.controller.base.BaseController;
import com.authine.cloudpivot.web.api.dubbo.DubboConfigService;
import com.authine.cloudpivot.web.api.service.CheckUserService;
import com.authine.cloudpivot.web.api.service.EmployeeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Api(description = "和记黄埔相关接口", tags = "员工接口")
@RestController
@RequestMapping("/public/employee")
@Slf4j
@Validated
public class EmployeeController extends BaseController {
    @Autowired
    private EmployeeService employeeService;


    @ApiOperation(value = "获取新员工工号")
    @PostMapping("/getnewemployeeno")
    public String getNewEmployeeNo(String companycode) {
        //ResultBean resultBean = new ResultBean();
        //int result = 0;
        int newUserNo = 0;
        String workPrefix = employeeService.GetWorkPrefix(companycode);
        if (workPrefix != null) {
            String maxCode = employeeService.GetMaxNo(workPrefix);
            if (maxCode !=null)
            {
                newUserNo=Integer.parseInt(maxCode) +1;
                return String.valueOf(newUserNo);
            }
            else
            {
                //If nobody found, that must be the no.1
                workPrefix= workPrefix+"0001";
                return workPrefix;
            }
        }
        else
        {
            return "company code is invalid";
        }
    }
}
